﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Model;
using AspNetCs.Bll;
using System.Data;
using System.Collections;
using AspNetCs.Enumerations;
using AspNetCs.Enumerations.memorial_enum;
using AspNetCs.Enumerations.User_Enum;
using AspNetCs.Common;
using AspNetCs.Enumerations.Channel_Enum;

public partial class Users_SendLeaveInfo : BasePage
{
    protected int types = 0;
    protected int channelID=0;
    protected string topPhotoPath = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        topPhotoPath = configInfo.InstallDir + "Images/historyphoto2.jpg";
        if (!IsPostBack)
        {
            types = StringHelper.isNumber_int(Request["types"]);
            ViewState["types"] = types;
            channelID = StringHelper.isNumber_int(Request["channelID"]);
            ViewState["channelID"] = channelID;
        }
        else
        {
            if (ViewState["channelID"]!=null)
            {
                channelID = StringHelper.isNumber_int(Request["channelID"]);
            }
            if (ViewState["types"]!=null)
            {
                types = StringHelper.isNumber_int(Request["types"]);
            }
        }
    }

    protected void btnSumbit_Click(object sender, EventArgs e)
    {
        if (Add())
        {
            ResultStr("ManageLeave.aspx?types=" + this.types + "&channelID="+this.channelID, "添加成功");
        }
        else
        {
            ResultStr("ManageLeave.aspx?types=" + this.types + "&channelID=" + this.channelID, "添加失败");
        }
    }

    public bool Add()
    {
        LeaveInfo model = new LeaveInfo();
        model.ChannelID = channelID;
        model.Email = StringHelper.HtmlEncrypt(StringHelper.FilterScript(txtEmail.Text));
        model.LeaveContent = StringHelper.HtmlEncrypt(StringHelper.FilterScript(txtContent.Text));
        model.LeaveName = StringHelper.HtmlEncrypt(StringHelper.FilterScript(txtName.Text));
        model.LeaveTime = DateTime.Now;
        model.LinkPic = StringHelper.HtmlEncrypt(StringHelper.FilterScript(txtPic.Text));
        model.Topic = StringHelper.HtmlEncrypt(StringHelper.FilterScript(txtTopic.Text));
        model.Types = types;
        if (model.ChannelID <= 0 || model.Types <= -1)
        {
            ResultStr("SendLeaveInfo.aspx", "添加失败");
            return false;
        }
        if (string.IsNullOrEmpty(model.Email))
        {
            Page.RegisterStartupScript("EmailEmpty","Email不能为空");
            return false;
        }
        if (string.IsNullOrEmpty(model.LeaveContent))
        {
            Page.RegisterStartupScript("ContentEmpty", "留言内容不能为空");
            return false;
        }
        if (string.IsNullOrEmpty(model.LeaveName))
        {
            Page.RegisterStartupScript("NameEmpty", "留言人不能为空");
            return false;
        }
        if (string.IsNullOrEmpty(model.Topic))
        {
            Page.RegisterStartupScript("TopicEmpty", "主题不能为空");
            return false;
        }
        return LeaveInfo_BLL.CreateNew.Add(model) > 0 ? true : false;
    }
}
